import mongoose, { Schema } from 'mongoose';

const schema = new Schema(
  {
    fromUser: { type: Schema.Types.ObjectId, ref: 'User' },
    toChannel: { type: Schema.Types.ObjectId, ref: 'Channel', index: true },
    subType: { type: String },
    body: { type: String },
    pinned: { type: Boolean },
    pinnedBy: { type: Schema.Types.ObjectId, ref: 'User' },
    createdAt: { type: Date, default: Date.now, index: true },
    updatedAt: { type: Date, default: Date.now },
    mentions: [{ type: Schema.Types.ObjectId, ref: 'Mention' }],
    isSent: { type: Number, default: 0 },
    fromSocialId: { type: String },
  },
  {
    collection: 'messages',
  },
);

export default mongoose.model('Message', schema);
